// 轮播图
let bannerApp = new Vue({
    el:"#bannerApp",
    data:{
        loopImage: []
    },
    methods:{
        loadLoopImage: function () {
            axios({
                url: "/gzbooksingle/dgLoopImage",
                method: "get"
            }).then(function (response) {
                bannerApp.loopImage = response.data;
                bannerApp.$nextTick(function () {
                    var mySwiper = new Swiper('#sc2', {
                        speed: 1000,
                        /*loop : true,*/
                        autoplay: 3000,
                        pagination : '.swiper-pagination',
                        paginationClickable: true,
                        paginationBulletRender: function (swiper, index, className) {
                            return '<span class="' + className + '">' + (index + 1) + '</span>';
                        }
                    })
                })

            })
        }
    },
    created: function () {
        this.loadLoopImage();

    }
})

// 卡卷
let cardApp = new Vue({
    el:"#cardApp",
    data:{
        cardSale: []
    },
    methods:{
        // 获取所有卡卷
        loadCardSale: function () {
            axios({
                url: "/gzbooksingle/dgCardSale",
                method: "get"
            }).then(function (response) {
                cardApp.cardSale = response.data;

            })
        },
        // 获取卡卷
        getCard:function (id) {

        }
    },
    created: function () {
        this.loadCardSale();
    }
})

// 新书上架
let newBookApp = new Vue({
    el:"#newBookApp",
    data:{
        newBooks: []
    },
    methods:{
        loadNewBook: function () {
            axios({
                url: "/gzbooksingle/dgBookInfo/new/1/10",
                method: "get"
            }).then(function (response) {
                newBookApp.newBooks = response.data.list;
                console.log(newBookApp.newBooks);
                newBookApp.$nextTick(function () {
                    var mClick = 0; //定义多次点击事件	改值等于0时移动完毕		等于1时正在移动
                    $("i.prev").click(function () {
                        if (mClick == 0) {
                            mClick = 1;
                            $(".newBook .main .list .bookList ul").prepend($(".newBook .main .list .bookList ul li:last-child"));
                            $(".bookList ul").css("margin-left", "-197px");
                            $(".bookList ul").animate({
                                "margin-left": "0"
                            }, 500, function () {
                                mClick = 0;
                            });
                        } else {
                            return false;
                        }
                    })

                    $("i.next").click(function () {
                        if (mClick == 0) {
                            mClick = 1;
                            $(".bookList ul").animate({
                                "margin-left": "-197px"
                            }, 500, function () {
                                $(".newBook .main .list .bookList ul").append($(".newBook .main .list .bookList ul li:first-child"));
                                $(".bookList ul").css("margin-left", "0");
                                mClick = 0;
                            });
                        } else {
                            return false;
                        }
                    })

                    //新书上架列表数量如果少于7个，隐藏左右切换按钮
                    var newBL = $(".newBook .main .list .bookList ul li").length;
                    if (newBL < 7) {
                        $(".newBook .main .list i").hide();
                    }
                })
            })
        }
    },
    created: function () {
        this.loadNewBook();
    },
    mounted: function(){

    }
})

// 每周推荐
let weekApp = new Vue({
    el:"#weekApp",
    data:{
        weekBooks: []
    },
    methods:{
        loadWeekBook: function () {
            axios({
                url: "/gzbooksingle/dgWeekRecommand",
                method: "get"
            }).then(function (response) {
                weekApp.weekBooks = response.data;
            })
        }
    },
    created: function () {
        this.loadWeekBook();
    }
})

// 推荐图书
let recommendApp = new Vue({
    el:"#recommendApp",
    data:{
        literature: [],
        children: [],
        life: [],
        science: [],
        multimedia: []
    },
    methods:{
        loadLiterature: function (response) {
            axios({
                url: "/gzbooksingle/dgBookInfo/booksByMenu/11/1/6",
                method: "get"
            }).then(function (response) {
                recommendApp.literature = response.data.list;
                console.log(recommendApp.literature)
            })
        },
        loadChildren: function (response) {
            axios({
                url: "/gzbooksingle/dgBookInfo/booksByMenu/36/1/6",
                method: "get"
            }).then(function (response) {
                recommendApp.children = response.data.list;
                console.log(recommendApp.children)
            })
        },
        loadLife: function (response) {
            axios({
                url: "/gzbooksingle/dgBookInfo/booksByMenu/54/1/6",
                method: "get"
            }).then(function (response) {
                recommendApp.life = response.data.list;
                console.log(recommendApp.life)
            })
        },
        loadScience: function (response) {
            axios({
                url: "/gzbooksingle/dgBookInfo/booksByMenu/72/1/6",
                method: "get"
            }).then(function (response) {
                recommendApp.science = response.data.list;
                console.log(recommendApp.science)
            })
        },
        loadMultimedia: function (response) {
            axios({
                url: "/gzbooksingle/dgBookInfo/booksByMenu/16/1/6",
                method: "get"
            }).then(function (response) {
                recommendApp.multimedia = response.data.list;
                console.log(recommendApp.multimedia)
            })
        },


    },
    created: function () {
        this.loadLiterature();
        this.loadChildren();
        this.loadLife();
        this.loadScience();
        this.loadMultimedia();
        bannerApp.$nextTick(function () {
            $(".column .leftColumn .sidebarNav ul li a").hover(function () {
                var index = $(this).parent().index();
                $(this).parent().addClass("cur").siblings().removeClass("cur");
                $(this).parents(".sidebarNav").siblings(".list").children("ul").eq(index).fadeIn().siblings().hide();
            }, function () {
            })
        })
    }
})
